<template>
  <!-- 添加或修改出厂试验-机械试验-间隔棒对话框 -->
  <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <el-form ref="form" :model="form" :rules="rules" label-width="200px">
      <el-tabs v-model="activeName" class="detail-tab" type="card">
        <el-tab-pane label="基本信息" name="first">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="抽检批次号" prop="batchNumber">
                <el-input v-model="form.batchNumber" placeholder="请输入抽检批次号"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="样品编号" prop="sampleNumber">
                <el-input v-model="form.sampleNumber" placeholder="请输入样品编号"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="检验时间" prop="inspectTime">
                <el-date-picker clearable
                                v-model="form.inspectTime"
                                type="date"
                                value-format="yyyy-MM-dd  HH:mm:ss"
                                placeholder="请选择尺寸检验时间">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="是否合格" prop="testPass">
                <el-radio-group v-model="form.testPass">
                  <el-radio
                    v-for="dict in dict.type.yes_no"
                    :key="dict.value"
                    :label="dict.value"
                  >{{ dict.label }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="顺线握力" prop="linePower">
                <el-input v-model="form.linePower" placeholder="请输入顺线握力" style="width:80%;"/>
                <el-tag style="margin-left: 10px;" v-for="standard in standardList" v-if="standard.propName==='linePower'"
                        type="danger">{{ standard.propValueMin }}-{{ standard.propValueMax }}
                </el-tag>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="扭握力矩（要求值）" prop="twistRequire">
                <el-input v-model="form.twistRequire" placeholder="请输入扭握力矩" style="width:80%;"/>
                <el-tag style="margin-left: 10px;" v-for="standard in standardList" v-if="standard.propName==='twistRequire'"
                        type="danger">{{ standard.propValueMin }}-{{ standard.propValueMax }}
                </el-tag>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="扭握力矩（实测值）" prop="twistTest">
                <el-input v-model="form.twistTest" placeholder="请输入扭握力矩" style="width:80%;"/>
                <el-tag style="margin-left: 10px;" v-for="standard in standardList" v-if="standard.propName==='twistTest'"
                        type="danger">{{ standard.propValueMin }}-{{ standard.propValueMax }}
                </el-tag>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="线夹本体破坏载荷（要求值）" prop="clampLoadRequire">
                <el-input v-model="form.clampLoadRequire" placeholder="请输入线夹本体破坏载荷" style="width:80%;"/>
                <el-tag style="margin-left: 10px;" v-for="standard in standardList" v-if="standard.propName==='clampLoadRequire'"
                        type="danger">{{ standard.propValueMin }}-{{ standard.propValueMax }}
                </el-tag>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="线夹本体破坏载荷（实测值）" prop="clampLoadTest">
                <el-input v-model="form.clampLoadTest" placeholder="请输入线夹本体破坏载荷" style="width:80%;"/>
                <el-tag style="margin-left: 10px;" v-for="standard in standardList" v-if="standard.propName==='clampLoadTest'"
                        type="danger">{{ standard.propValueMin }}-{{ standard.propValueMax }}
                </el-tag>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="线夹间拉力（要求值）" prop="clampPullRequire">
                <el-input v-model="form.clampPullRequire" placeholder="请输入线夹间拉力" style="width:80%;"/>
                <el-tag style="margin-left: 10px;" v-for="standard in standardList" v-if="standard.propName==='clampPullRequire'"
                        type="danger">{{ standard.propValueMin }}-{{ standard.propValueMax }}
                </el-tag>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="线夹间拉力（实测值）" prop="clampPullTest">
                <el-input v-model="form.clampPullTest" placeholder="请输入线夹间拉力" style="width:80%;"/>
                <el-tag style="margin-left: 10px;" v-for="standard in standardList" v-if="standard.propName==='clampPullTest'"
                        type="danger">{{ standard.propValueMin }}-{{ standard.propValueMax }}
                </el-tag>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="线夹间压力（要求值）" prop="clampPressureRequire">
                <el-input v-model="form.clampPressureRequire" placeholder="请输入线夹间压力" style="width:80%;"/>
                <el-tag style="margin-left: 10px;" v-for="standard in standardList" v-if="standard.propName==='clampPressureRequire'"
                        type="danger">{{ standard.propValueMin }}-{{ standard.propValueMax }}
                </el-tag>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="线夹间压力（实测值）" prop="clampPressureTest">
                <el-input v-model="form.clampPressureTest" placeholder="请输入线夹间压力" style="width:80%;"/>
                <el-tag style="margin-left: 10px;" v-for="standard in standardList" v-if="standard.propName==='clampPressureTest'"
                        type="danger">{{ standard.propValueMin }}-{{ standard.propValueMax }}
                </el-tag>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="向心力要求值" prop="centerStrengthRequire">
                <el-input v-model="form.centerStrengthRequire" placeholder="请输入向心力要求值" style="width:80%;"/>
                <el-tag style="margin-left: 10px;" v-for="standard in standardList" v-if="standard.propName==='centerStrengthRequire'"
                        type="danger">{{ standard.propValueMin }}-{{ standard.propValueMax }}
                </el-tag>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="向心力实测值" prop="centerStrengthTest">
                <el-input v-model="form.centerStrengthTest" placeholder="请输入向心力实测值" style="width:80%;"/>
                <el-tag style="margin-left: 10px;" v-for="standard in standardList" v-if="standard.propName==='centerStrengthTest'"
                        type="danger">{{ standard.propValueMin }}-{{ standard.propValueMax }}
                </el-tag>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="质检报告" prop="reportFile">
                <file-upload v-model="form.reportFile"/>
              </el-form-item>
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {addAction, getAction, getById, updateAction} from '@/api/manage';
import moment from 'moment';
import {parseTime} from "@/utils/common";

export default {
  name: "FactoryTestMachineryStickForm",
  dicts: ['yes_no'],
  data() {
    return {
      // 遮罩层
      loading: true,
      activeName: "first",
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      url: {
        getById: '/factoryTestMachineryStick/factoryTestMachineryStick/',
        add: '/factoryTestMachineryStick/factoryTestMachineryStick/add',
        edit: '/factoryTestMachineryStick/factoryTestMachineryStick/edit',
      },
      standardList: []
    };
  },
  created() {

  },
  methods: {
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        projectId: null,
        orderId: null,
        goodsId: null,
        goodsName: null,
        goodsModel: null,
        batchNumber: null,
        sampleNumber: null,
        inspectTime: parseTime(new Date(), '{y}-{m}-{d} {h}:{i}:{s}'),
        linePower: null,
        twistRequire: null,
        twistTest: null,
        clampLoadRequire: null,
        clampLoadTest: null,
        clampPullRequire: null,
        clampPullTest: null,
        clampPressureRequire: null,
        clampPressureTest: null,
        centerStrengthRequire: null,
        centerStrengthTest: null,
        testPass: '1',
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加机械试验-间隔棒";
    },
    /** 新增按钮操作 */
    handleAddByWorkOrderId(workOrderId,goodsId) {
      this.reset();
      this.form.workOrderId = workOrderId;
      this.form.goodsId = goodsId;
      this.open = true;
      this.title = "添加机械试验-间隔棒";
    },
    /** 新增按钮操作 */
    handleAddByDaohuoDetailId(daohuoDetailId,goodsId) {
      this.reset();
      this.form.daohuoDetailId = daohuoDetailId;
      this.form.goodsId = goodsId;
      this.open = true;
      this.title = "添加机械试验-间隔棒";
    },

    /** 新增按钮操作 */
    handleAddByProduceDetailId(produceRecordDetailId,goodsId) {
      this.reset();
      this.form.produceRecordDetailId = produceRecordDetailId;
      this.form.goodsId = goodsId;
      this.open = true;
      this.title = "添加机械试验-间隔棒";
    },

    /** 新增按钮操作 */
    handleAddByFahuoDetailId(fahuoDetailId) {
      this.reset();
      this.form.fahuoDetailId = fahuoDetailId;
      this.open = true;
      this.title = "添加机械试验-间隔棒";
    },

    /** 新增按钮操作 */
    handleAddByRukuId(rukuId,goodsId) {
      this.reset();
      this.form.rukuId = rukuId;
      this.form.goodsId = goodsId;
      this.open = true;
      this.title = "添加机械试验-间隔棒";
    },

    /** 新增按钮操作 */
    handleAddByGoodsSaleId(goodsSaleId,goodsId) {
      this.reset();
      this.form.goodsSaleId = goodsSaleId;
      this.form.goodsId = goodsId;
      this.open = true;
      this.title = "添加机械试验-间隔棒";
    },

    /** 新增按钮操作 */
    handleAddBySampleId(sampleId, goodsId, goodsSaleId) {
      this.reset();
      this.form.sampleId = sampleId;
      this.form.goodsId = goodsId;
      this.form.goodsSaleId = goodsSaleId;
      this.open = true;
      this.title = "添加机械试验-间隔棒";
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getById(this.url.getById, id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改机械试验-间隔棒";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAction(this.url.edit, this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.$emit('ok');
            });
          } else {
            addAction(this.url.add, this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.$emit('ok');
            });
          }
        }
      });
    },

    getStandardList() {
      let name = "factory_test_machinery_stick";
      let goodsId = this.form.goodsId;
      getAction('/factoryTestStandard/factoryTestStandard/getTableColumns/' + name + "/" + goodsId, {}).then(response => {
        this.loading = false;
        this.standardList = response.data;
      });
    },


  }
};
</script>
